//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    transformX: -10,
    transformY: -10
  },
  onLoad: function () {
    
  },
  onShow: function () {
    var that = this;
    wx.startDeviceMotionListening({
      success: function (res) {
        console.log("startDeviceMotionListening:", res);
      }
    })
    wx.onDeviceMotionChange(res => {
      console.log('res: ', res);
      var { alpha, beta, gamma } = res;
      /* a = obj.lon < 180 ? obj.lon : obj.lon - 360;
      b = b > 0 ? b > -180 ? 0 : b : b < -160 ? -20 : b; */

      // console.log([a, b]);
      /* that.setData({
        transformX: a,
        transformY: b
      }) */
    })
  },
  onUnload: function() {
    wx.stopDeviceMotionListening({
      success: function (res) {
        console.log("stopDeviceMotionListening:", res);
      }
    })
    wx.offDeviceMotionChange({
      success: function (res) {
        console.log("offDeviceMotionChange:", res);
      }
    })
  },
})
